package com.ruoyi.supervise.service.impl.decisupport;

import java.text.DecimalFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.supervise.domain.decisupport.ConstructionProject;
import com.ruoyi.supervise.domain.decisupport.MunicipalEngineering;
import com.ruoyi.supervise.domain.decisupport.MyBigDataAllProHoursPro;
import com.ruoyi.supervise.domain.decisupport.ProportionOfProjectType;
import com.ruoyi.supervise.mapper.decisupport.ProportionOfProjectTypeMapper;
import com.ruoyi.supervise.service.decisupport.ProportionOfProjectTypeService;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class ProportionOfProjectTypeServiceImpl implements ProportionOfProjectTypeService{

    @Autowired
    private ProportionOfProjectTypeMapper proportionOfProjectTypeMapper;

	@Override
	public List<ProportionOfProjectType> FJProportionOfProjectType(ProportionOfProjectType ppt) {
		// TODO Auto-generated method stub
		return proportionOfProjectTypeMapper.FJProportionOfProjectType(ppt);
	}

	@Override
	public List<ProportionOfProjectType> FJProportionOfProjectTypeBT(MyBigDataAllProHoursPro bd) {
		ProportionOfProjectType ppt=new ProportionOfProjectType();
		ppt.setTimeNowBegin(bd.getTimeNowBegin());
		ppt.setTimeNowEnd(bd.getTimeNowEnd());
		ppt.setProjectCityNum(bd.getProjectCityNum());
		ppt.setIsPrivateConstruction(bd.getIsPrivateConstruction());
		ppt.setEngineeringType("房屋建筑工程");
		List<ProportionOfProjectType> pptList=proportionOfProjectTypeMapper.FJProportionOfProjectType(ppt);
		Long totalProjectNum = 0L;
		for(ProportionOfProjectType p:pptList)
		{
			totalProjectNum=totalProjectNum+p.getProjectNum();
		}
		for(ProportionOfProjectType p:pptList)
		{
			DecimalFormat df = new DecimalFormat("0.00");
		    String proportion = df.format(((float) p.getProjectNum() / (totalProjectNum)) * 100);
		    p.setProportion(proportion);
		    String projectNumStr=df.format(p.getProjectNum());
		    p.setProjectNumStr(projectNumStr);
		}
		return pptList;
	}

	@Override
	public List<ProportionOfProjectType> ProportionOfProjectType(ProportionOfProjectType ppt) {
		// TODO Auto-generated method stub
		return proportionOfProjectTypeMapper.ProportionOfProjectType(ppt);
	}

	@Override
	public List<ProportionOfProjectType> AllProportionOfProjectTypeBT(ConstructionProject cp) {
		ProportionOfProjectType ppt=new ProportionOfProjectType();
		ppt.setTimeNowBegin(cp.getTimeNowBegin());
		ppt.setTimeNowEnd(cp.getTimeNowEnd());
		ppt.setProjectCityNum(cp.getProjectCityNum());
		ppt.setIsPrivateConstruction(cp.getIsPrivateConstruction());
		List<ProportionOfProjectType> pptList=proportionOfProjectTypeMapper.ProportionOfProjectType(ppt);
		Long totalProjectNum = 0L;
		for(ProportionOfProjectType p:pptList)
		{
			totalProjectNum=totalProjectNum+p.getProjectNum();
		}
		for(ProportionOfProjectType p:pptList)
		{
			DecimalFormat df = new DecimalFormat("0.00");
		    String proportion = df.format(((float) p.getProjectNum() / (totalProjectNum)) * 100);
		    p.setProportion(proportion);
		    String projectNumStr=df.format(p.getProjectNum());
		    p.setProjectNumStr(projectNumStr);
		}
		return pptList;
	}

	@Override
	public List<ProportionOfProjectType> MEProportionOfProjectTypeBT(MunicipalEngineering me) {
		ProportionOfProjectType ppt=new ProportionOfProjectType();
		ppt.setTimeNowBegin(me.getTimeNowBegin());
		ppt.setTimeNowEnd(me.getTimeNowEnd());
		ppt.setIsPrivateConstruction(me.getIsPrivateConstruction());
		ppt.setEngineeringType("市政工程");
		ppt.setProjectCityNum(me.getProjectCityNum());
		List<ProportionOfProjectType> pptList=proportionOfProjectTypeMapper.ProportionOfProjectType(ppt);
		Long totalProjectNum = 0L;
		for(ProportionOfProjectType p:pptList)
		{
			totalProjectNum=totalProjectNum+p.getProjectNum();
		}
		for(ProportionOfProjectType p:pptList)
		{
			DecimalFormat df = new DecimalFormat("0.00");
		    String proportion = df.format(((float) p.getProjectNum() / (totalProjectNum)) * 100);
		    p.setProportion(proportion);
		    String projectNumStr=df.format(p.getProjectNum());
		    p.setProjectNumStr(projectNumStr);
		}
		return pptList;
	}
}
